﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BF.Model;
using BF.IBLL.Dictionary;
using Base.Core.UnityFactory;
using BF.IBLL.BaseSystem;

namespace BF.Web.App_Code
{
    public static class UICommon
    {
        private static List<dic_Dict> _DictList;
        private static string strDate = DateTime.Now.ToString("yyyy-MM-dd");
        /// <summary>
        /// 缓存中的系统字典集合
        /// </summary>
        public static List<dic_Dict> DictList
        {
            get
            {
                if (strDate != DateTime.Now.ToString("yyyy-MM-dd"))
                {
                    UpdateAllList();
                }
                if (_DictList == null)
                {
                    UpdateDictList();
                }
                return _DictList;
            }
        }


        /// <summary>
        /// 更新缓存中所有的集合(新增缓存时请在此注册)
        /// </summary>
        private static void UpdateAllList()
        {
            UpdateDictList();
            strDate = DateTime.Now.ToString("yyyy-MM-dd");
        }

        /// <summary>
        /// 更新缓存中的标准字典表 默认排序字段：iSort 升序
        /// </summary>
        public static void UpdateDictList()
        {
            Idic_DictBLL bll = IOCFactory.GetIOCResolve<Idic_DictBLL>();
            _DictList = bll.GetList(P => true).OrderBy(p => p.iSort).ToList();
         }
    }
}